﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LastfmNet.Tests
{
    [TestClass]
    public class AlbumApiUnitTests
    {
        [TestMethod]
        [Ignore()] // Requires user authentication.
        public void TestAddTags()
        {
            // TODO: Test AddTags(string artist, string album)
        }

        [TestMethod]
        public void TestGetBuylinksByArtistAndAlbum()
        {
            var buyLinks = Global.Lastfm.Album.GetBuylinks(artist: "radiohead", album: "in rainbows", country: "united kingdom");
            Console.WriteLine("Downloads:");
            foreach (var item in buyLinks.Downloads)
            {
                Console.WriteLine(string.Format("{0} {1} {2}", item.SupplierName, item.Price.Amount, item.Price.Currency));
            }
            Console.WriteLine();
            Console.WriteLine("Physicals:");
            foreach (var item in buyLinks.Physicals)
            {
                Console.WriteLine(string.Format("{0} {1} {2}", item.SupplierName, item.Price.Amount, item.Price.Currency));
            }
        }

        [TestMethod]
        public void TestGetBuylinksByMbid()
        {
            var buyLinks = Global.Lastfm.Album.GetBuylinks(mbid: "61bf0388-b8a9-48f4-81d1-7eb02706dfb0", country: "united kingdom");
            Console.WriteLine("Downloads:");
            foreach (var item in buyLinks.Downloads)
            {
                Console.WriteLine(string.Format("{0} {1} {2}", item.SupplierName, item.Price.Amount, item.Price.Currency));
            }
            Console.WriteLine();
            Console.WriteLine("Physicals:");
            foreach (var item in buyLinks.Physicals)
            {
                Console.WriteLine(string.Format("{0} {1} {2}", item.SupplierName, item.Price.Amount, item.Price.Currency));
            }
        }

        [TestMethod]
        public void TestGetInfoByArtistAndAlbum()
        {
            var album = Global.Lastfm.Album.GetInfo(artist: "Cher", album: "Believe");
            var tracks = album.Tracks;
            Console.WriteLine("Correct artist: " + album.Artist);
            Console.WriteLine("Correct album: " + album.Name);
            Console.WriteLine();
            foreach (var track in tracks)
            {
                Console.WriteLine(string.Format("{0}. {1} - {2}", track.Rank, track.Artist.Name, track.Name));
            }
        }

        [TestMethod]
        public void TestGetInfoByMbid()
        {
            var album = Global.Lastfm.Album.GetInfo(mbid: "61bf0388-b8a9-48f4-81d1-7eb02706dfb0");
            var tracks = album.Tracks;
            foreach (var track in tracks)
            {
                Console.WriteLine(string.Format("{0}. {1} - {2}", track.Rank, track.Artist.Name, track.Name));
            }
        }

        [TestMethod]
        public void TestGetShoutsByArtistAndAlbum()
        {
            string artist = "cher";
            string album = "believe";
            var shoutsPager = Global.Lastfm.Album.GetShouts(artist: ref artist, album: ref album, autocorrect: true);
            Console.WriteLine("Correct artist: " + artist);
            Console.WriteLine("Correct album: " + album);
            Console.WriteLine();
            foreach (var shout in shoutsPager.ItemsList)
            {
                Console.WriteLine(string.Format("{0} ({1}) : {2}", shout.Author, shout.Date, shout.Body));
            }
        }

        [TestMethod]
        public void TestGetShoutsByMbid()
        {
            var shoutsPager = Global.Lastfm.Album.GetShouts("61bf0388-b8a9-48f4-81d1-7eb02706dfb0");
            foreach (var shout in shoutsPager.ItemsList)
            {
                Console.WriteLine(string.Format("{0} ({1}) : {2}", shout.Author, shout.Date, shout.Body));
            }
        }

        [TestMethod]
        [Ignore()] // Requires user authentication.
        public void TestGetTags()
        {
        }

        [TestMethod]
        public void TestGetTopTags()
        {
            string artist = "cher";
            string album = "believe";
            var topTags = Global.Lastfm.Album.GetTopTags(artist: ref artist, album: ref album, autocorrect: true);
            Console.WriteLine("Correct artist: " + artist);
            Console.WriteLine("Correct album: " + album);
            Console.WriteLine();
            foreach (var topTag in topTags.ItemsList)
            {
                Console.WriteLine(string.Format("{0} ({1})", topTag.Name, topTag.Count));
            }
        }

        [TestMethod]
        [Ignore()] // Requires user authentication.
        public void TestRemoveTag()
        {
        }

        [TestMethod]
        public void TestSearch()
        {
            var searchResults = Global.Lastfm.Album.Search("believe");
            foreach (var album in searchResults.ItemsList)
            {
                Console.WriteLine("{0} - {1}", album.Artist, album.Name);
            }
        }

        [TestMethod]
        [Ignore()] // Requires user authentication.
        public void TestShare()
        {
        }
    }
}
